package com.tron.nettychat.controller;

import com.github.tobato.fastdfs.domain.fdfs.MetaData;
import com.github.tobato.fastdfs.domain.fdfs.StorePath;
import com.github.tobato.fastdfs.domain.upload.FastImageFile;
import com.github.tobato.fastdfs.service.FastFileStorageClient;
import org.apache.commons.io.IOUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RestController;

import java.io.BufferedInputStream;
import java.io.File;
import java.io.FileInputStream;
import java.io.FileNotFoundException;
import java.util.HashSet;


@RestController
public class TronFileController {
    @Autowired
    FastFileStorageClient fastFileStorageClient;

    @GetMapping("/uploadImage")
    public String uploadImage() throws FileNotFoundException {
        File file = new File("D:src/main/resources/1.png");
        BufferedInputStream inputStream = IOUtils.buffer(new FileInputStream(file));
        HashSet<MetaData> set = new HashSet<>();
        MetaData metaData = new MetaData();
        metaData.setName("a");
        metaData.setValue("a");
        set.add(metaData);
        FastImageFile fastImageFile = new FastImageFile(inputStream,file.length(),"png",set);
        StorePath storePath = fastFileStorageClient.uploadImage(fastImageFile);
        return storePath.getFullPath();
    }


}
